import 'package:flutter/material.dart';
import '../widgets/preview/enhanced_audio_preview.dart';
import 'package:url_launcher/url_launcher.dart';

class AudioPlayerPage extends StatelessWidget {
  final String audioUrl;
  final String? fileName;
  final int? fileId;
  final String? extension;
  final String? mimeType;
  final int? fileSize;

  const AudioPlayerPage({
    Key? key,
    required this.audioUrl,
    this.fileName,
    this.fileId,
    this.extension,
    this.mimeType,
    this.fileSize,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(fileName ?? '音频播放器'),
        actions: [
          // 下载按钮
          IconButton(
            icon: const Icon(Icons.download),
            tooltip: '下载音频',
            onPressed: () {
              // 使用EnhancedAudioPreview内部的下载功能
              final url = Uri.parse(audioUrl);
              launchUrl(url, mode: LaunchMode.externalApplication);
            },
          ),
        ],
      ),
      body: EnhancedAudioPreview(
        previewUrl: audioUrl,
        fileName: fileName,
        extension: extension,
        mimeType: mimeType,
        fileSize: fileSize,
      ),
    );
  }
}
